package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SupplyCategroy;
import com.ruoyi.system.service.ISupplyCategroyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 基础分类Controller
 * 
 * @author ruoyi
 * @date 2025-08-19
 */
@RestController
@RequestMapping("/system/supplyCategroy")
public class SupplyCategroyController extends BaseController
{
    @Autowired
    private ISupplyCategroyService supplyCategroyService;

    /**
     * 查询基础分类树
     */
    @RequestMapping("/getJsonData")
    public AjaxResult getJsonData()
    {
        SupplyCategroy supplyCategroy = new SupplyCategroy();

        AjaxResult ajax = supplyCategroyService.getJsonData(supplyCategroy);
        return ajax;
    }

    /**
     * 查询基础分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:supplyCategroy:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplyCategroy supplyCategroy)
    {
        startPage();
        List<SupplyCategroy> list = supplyCategroyService.selectSupplyCategroyList(supplyCategroy);
        return getDataTable(list);
    }

    /**
     * 导出基础分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:supplyCategroy:export')")
    @Log(title = "基础分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplyCategroy supplyCategroy)
    {
        List<SupplyCategroy> list = supplyCategroyService.selectSupplyCategroyList(supplyCategroy);
        ExcelUtil<SupplyCategroy> util = new ExcelUtil<SupplyCategroy>(SupplyCategroy.class);
        util.exportExcel(response, list, "基础分类数据");
    }

    /**
     * 获取基础分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:supplyCategroy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(supplyCategroyService.selectSupplyCategroyById(id));
    }

    /**
     * 新增基础分类
     */
    @PreAuthorize("@ss.hasPermi('system:supplyCategroy:add')")
    @Log(title = "基础分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplyCategroy supplyCategroy)
    {
        return toAjax(supplyCategroyService.insertSupplyCategroy(supplyCategroy));
    }

    /**
     * 修改基础分类
     */
    @PreAuthorize("@ss.hasPermi('system:supplyCategroy:edit')")
    @Log(title = "基础分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplyCategroy supplyCategroy)
    {
        return toAjax(supplyCategroyService.updateSupplyCategroy(supplyCategroy));
    }

    /**
     * 删除基础分类
     */
    @PreAuthorize("@ss.hasPermi('system:supplyCategroy:remove')")
    @Log(title = "基础分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(supplyCategroyService.deleteSupplyCategroyByIds(ids));
    }
}
